
#ifndef FILEREADERCPP
#define FILEREADERCPP

#include<iostream>
#include"fileReader.hpp"

bool isAlpha(char ch){
	return isLower(ch)||isUpper(ch)||ch=='_';
}
bool isDigit(char ch){
	return '0'<=ch&&ch<='9';
}
bool isLower(char ch){
	return 'a'<=ch&&ch<='z';
}
bool isUpper(char ch){
	return 'A'<=ch&&ch<='Z';
}

bool reachEnd(FILE* file){
	char ch=fgetc(file);
	if(ch==EOF)return true;
	fseek(file,-1,SEEK_CUR);
	return false;
}

void readLine(FILE* file,std::string& buffer){
	buffer.clear();
	char ch=fgetc(file);
	while(ch!='\n'&&ch!=EOF){
		buffer.push_back(ch);
		ch=fgetc(file);
	}
}

std::string getString(std::string& str,int l,int r){
	std::string ans;
	for(int i=l;i<=r;i++)
		ans.push_back(str[i]);
	return ans;
}

// this funtion only works with expression with '\' now
// specifically: '\n' '\t' '\r'
// can be easily enlarged .. maybe
// the para p would goto last read position
char getCharInString(std::string& str,int& p) {
	char ret = 0;
	
	if(str[p] == '\\') {
		if(p == str.length() - 1) return -1;
		p++;
		switch (str[p])
		{
		case 'n': ret = '\n'; break;
		case 't': ret = '\t'; break;
		case 'r': ret = '\r'; break;
		
		default:
			ret = str[p];
			break;
		}
	}else {
		ret = str[p];
	}
	return ret;
}


#endif